class Solution
{
public:
    vector<vector<int>> mergeSimilarItems(vector<vector<int>> &items1, vector<vector<int>> &items2)
    {
        map<int, int> itemValues;
        for (auto &item : items1)
        {
            itemValues[item[0]] += item[1];
        }
        for (auto &item : items2)
        {
            itemValues[item[0]] += item[1];
        }
        vector<vector<int>> result;
        for (auto &[item, value] : itemValues)
        {
            result.push_back({item, value});
        }
        return result;
    }
};